package com.xiaozhi.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * 健康数据分析实体类
 * 用于存储用户健康数据的分析结果和趋势
 *
 * @author xiaozhi
 * @since 2024-01-15
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("health_analytics")
public class HealthAnalytics implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 用户ID
     */
    @TableField("user_id")
    private Long userId;

    /**
     * 分析类型
     * VITAL_SIGNS: 生命体征分析
     * HEALTH_TREND: 健康趋势分析
     * RISK_ASSESSMENT: 风险评估
     * SYMPTOM_PATTERN: 症状模式分析
     * MEDICATION_ADHERENCE: 用药依从性分析
     */
    @TableField("analysis_type")
    private String analysisType;

    /**
     * 分析时间范围开始
     */
    @TableField("start_date")
    private LocalDateTime startDate;

    /**
     * 分析时间范围结束
     */
    @TableField("end_date")
    private LocalDateTime endDate;

    /**
     * 分析结果数据（JSON格式）
     * 包含图表数据、统计指标、趋势分析等
     */
    @TableField("analysis_data")
    private String analysisData;

    /**
     * 分析摘要
     */
    @TableField("summary")
    private String summary;

    /**
     * 健康评分（0-100）
     */
    @TableField("health_score")
    private Integer healthScore;

    /**
     * 风险等级
     * LOW: 低风险
     * MEDIUM: 中风险
     * HIGH: 高风险
     * CRITICAL: 危险
     */
    @TableField("risk_level")
    private String riskLevel;

    /**
     * 关键指标变化
     * 记录重要健康指标的变化情况
     */
    @TableField("key_changes")
    private String keyChanges;

    /**
     * 健康建议
     */
    @TableField("recommendations")
    private String recommendations;

    /**
     * 异常指标
     * 记录超出正常范围的健康指标
     */
    @TableField("abnormal_indicators")
    private String abnormalIndicators;

    /**
     * 趋势方向
     * IMPROVING: 改善
     * STABLE: 稳定
     * DECLINING: 下降
     * FLUCTUATING: 波动
     */
    @TableField("trend_direction")
    private String trendDirection;

    /**
     * 数据来源
     * MANUAL: 手动录入
     * DEVICE: 设备同步
     * ASSESSMENT: 评估生成
     * MIXED: 混合来源
     */
    @TableField("data_source")
    private String dataSource;

    /**
     * 分析状态
     * PROCESSING: 分析中
     * COMPLETED: 已完成
     * FAILED: 分析失败
     */
    @TableField("status")
    private String status;

    /**
     * 是否已读
     */
    @TableField("is_read")
    private Boolean isRead;

    /**
     * 分析版本
     * 用于追踪分析算法的版本
     */
    @TableField("analysis_version")
    private String analysisVersion;

    /**
     * 创建时间
     */
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    private LocalDateTime createdAt;

    /**
     * 更新时间
     */
    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;

    /**
     * 创建者ID
     */
    @TableField(value = "created_by", fill = FieldFill.INSERT)
    private Long createdBy;

    /**
     * 更新者ID
     */
    @TableField(value = "updated_by", fill = FieldFill.INSERT_UPDATE)
    private Long updatedBy;

    /**
     * 逻辑删除标志
     */
    @TableLogic
    @TableField("deleted")
    private Boolean deleted;

    // 辅助方法

    /**
     * 获取分析数据的Map形式
     */
    public Map<String, Object> getAnalysisDataMap() {
        // 这里可以添加JSON解析逻辑
        return null;
    }

    /**
     * 设置分析数据的Map形式
     */
    public void setAnalysisDataMap(Map<String, Object> dataMap) {
        // 这里可以添加JSON序列化逻辑
    }
    
    // 手动添加setter方法以解决编译问题
    public void setUserId(Long userId) {
        this.userId = userId;
    }
    
    public void setAnalysisType(String analysisType) {
        this.analysisType = analysisType;
    }
    
    public void setStartDate(LocalDateTime startDate) {
        this.startDate = startDate;
    }
    
    public void setEndDate(LocalDateTime endDate) {
        this.endDate = endDate;
    }
    
    public void setAnalysisData(String analysisData) {
        this.analysisData = analysisData;
    }
    
    public void setSummary(String summary) {
        this.summary = summary;
    }
    
    public void setHealthScore(Integer healthScore) {
        this.healthScore = healthScore;
    }
    
    public void setRiskLevel(String riskLevel) {
        this.riskLevel = riskLevel;
    }
    
    public void setRecommendations(String recommendations) {
        this.recommendations = recommendations;
    }
    
    public void setTrendDirection(String trendDirection) {
        this.trendDirection = trendDirection;
    }
    
    public void setStatus(String status) {
        this.status = status;
    }
    
    public void setIsRead(Boolean isRead) {
        this.isRead = isRead;
    }
    
    public void setAnalysisVersion(String analysisVersion) {
        this.analysisVersion = analysisVersion;
    }
    
    public void setDataSource(String dataSource) {
        this.dataSource = dataSource;
    }
    
    public void setAbnormalIndicators(String abnormalIndicators) {
        this.abnormalIndicators = abnormalIndicators;
    }
    
    public void setKeyChanges(String keyChanges) {
        this.keyChanges = keyChanges;
    }
    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public Long getUserId() {
        return this.userId;
    }
    
    public String getAnalysisType() {
        return this.analysisType;
    }
    
    public LocalDateTime getStartDate() {
        return this.startDate;
    }
    
    public LocalDateTime getEndDate() {
        return this.endDate;
    }
    
    public String getAnalysisData() {
        return this.analysisData;
    }
    
    public String getSummary() {
        return this.summary;
    }
    
    public Integer getHealthScore() {
        return this.healthScore;
    }
    
    public String getRiskLevel() {
        return this.riskLevel;
    }
    
    public String getRecommendations() {
        return this.recommendations;
    }
    
    public String getTrendDirection() {
        return this.trendDirection;
    }
    
    public String getStatus() {
        return this.status;
    }
    
    public Boolean getIsRead() {
        return this.isRead;
    }
    
    public String getAnalysisVersion() {
        return this.analysisVersion;
    }
    
    public String getDataSource() {
        return this.dataSource;
    }
    
    public String getAbnormalIndicators() {
        return this.abnormalIndicators;
    }
    
    public String getKeyChanges() {
        return this.keyChanges;
    }
    
    public LocalDateTime getCreatedAt() {
        return this.createdAt;
    }
    
    public LocalDateTime getUpdatedAt() {
        return this.updatedAt;
    }

    /**
     * 判断是否为高风险
     */
    public boolean isHighRisk() {
        return "HIGH".equals(riskLevel) || "CRITICAL".equals(riskLevel);
    }

    /**
     * 判断趋势是否在改善
     */
    public boolean isImproving() {
        return "IMPROVING".equals(trendDirection);
    }

    /**
     * 获取风险等级的中文描述
     */
    public String getRiskLevelText() {
        switch (riskLevel) {
            case "LOW":
                return "低风险";
            case "MEDIUM":
                return "中风险";
            case "HIGH":
                return "高风险";
            case "CRITICAL":
                return "危险";
            default:
                return "未知";
        }
    }

    /**
     * 获取趋势方向的中文描述
     */
    public String getTrendDirectionText() {
        switch (trendDirection) {
            case "IMPROVING":
                return "改善";
            case "STABLE":
                return "稳定";
            case "DECLINING":
                return "下降";
            case "FLUCTUATING":
                return "波动";
            default:
                return "未知";
        }
    }

    /**
     * 获取分析类型的中文描述
     */
    public String getAnalysisTypeText() {
        switch (analysisType) {
            case "VITAL_SIGNS":
                return "生命体征分析";
            case "HEALTH_TREND":
                return "健康趋势分析";
            case "RISK_ASSESSMENT":
                return "风险评估";
            case "SYMPTOM_PATTERN":
                return "症状模式分析";
            case "MEDICATION_ADHERENCE":
                return "用药依从性分析";
            default:
                return "未知类型";
        }
    }
}